package com.pocket.insight.base.utils;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.io.UnsupportedEncodingException;

/**
 * 描述：
 *
 * @author shuize
 * @create 2024/11/30
 */
@Slf4j
public class BytesUtil {

    public static String bytesToString(byte[] bytes, String charset) {
        String s;
        if (bytes == null) {
            return null;
        }

        if (StringUtils.isNotEmpty(charset)) {
            try {
                s = new String(bytes, charset);
            } catch (UnsupportedEncodingException e) {
                log.error(e.getMessage(), e);
                s = new String(bytes);
            }
        } else {
            s = new String(bytes);
        }
        return s;
    }
}
